const app = getApp()
import {
    wxfileTobase64,
    inputchange
} from '../../../../../utils/util.js'
import {
    ocrIdCard
} from '../../../../../api/app.js'
Component({
    data: {
        cardId: '',
        name: ''
    },
    methods: {
        inputchange(event) {
            inputchange(event, this)
        },
        submit() {
            this.data.name = this.data.name.replace(/\s/g, '');
            this.data.cardId = this.data.cardId.replace(/\s/g, '');
            // var regPos = /^\d+(\.\d+)?$/; 
            if(/[0-9]/.test(this.data.name)){
                app.toast('姓名不可携带数字')
                return 0
            }
            if (!this.data.name) {
                app.toast('请输入姓名！')
                return 0
            }
            console.log(this.data)
            if (!/^\d{17}[\dXx]$/.test(this.data.cardId)) {
                app.toast('请输入身份证！')
                return 0
            }
            this.triggerEvent('submit',{
                name: this.data.name,
                cardNo: this.data.cardId
            })
            
        },
        close() {
            this.triggerEvent('cancel')
        },
        camera() {
            wx.chooseImage({
                count: 1,
                sizeType: ['compressed'],
                sourceType: ['camera','album'],
                success: res=> {
                    console.log(res)
                    wxfileTobase64(res.tempFilePaths[0]).then(res => {
                        console.log(res)
                        ocrIdCard({
                            idCard: res
                        }).then(res => {
                            this.setData({
                                name: res.idCardInfo.name,
                                cardId: res.idCardInfo.code
                            })
                        })
                    })
                }
            })
        }
    }

})
